package com.stefanie.eventlistenerdemo.controller;

import com.stefanie.eventlistenerdemo.domain.dto.UserDto;
import com.stefanie.eventlistenerdemo.service.UserService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

/**
 * @author: stefanie-zy
 * @time: 2024/1/12-15:06
 * @description: 控制层-用户
 */
@RequestMapping(value = "/user")
@RestController
@Slf4j
@RequiredArgsConstructor
public class UserController {

    private int count = 0;

    private final UserService userService;

    /**
     * 新增用户
     *
     * @param userDto 用户信息
     * @return 新增结果
     */
    @PostMapping(value = "")
    public String save(@RequestBody UserDto userDto) {
        userService.save(userDto);
        return "user add successful!";
    }

    @GetMapping(value = "/stefanie-test")
    public String stefanie() {
        return "This is a test user with username Stefanie and password 123456";
    }

    @GetMapping(value = "/missMa")
    public String missMa() {
        count++;
        log.info("Request number {}", count);
        return "This is a test user with username Miss Ma and password 123456";
    }

    @GetMapping(value = "/test")
    public String test() {
        return "This is a test user with username Test and password 123456";
    }
}
